<template>
	<div class="shareCtrl" flex>
		<div flex="cross:center" class="textLeft" flex-box="1" @click="share('shareAppMessage',0)">
			<img src="./images/weixin.png" class="weixinIcon"/>
			<div class="shareText">微信</div>
		</div>
		<div flex="cross:center main:center" class="textCenter" flex-box="1" @click="share('shareTimeline',1)">
			<img src="./images/pengyouquan.png" class="pengyouquanIcon"/>
			<div class="shareText">朋友圈</div>
		</div>
		<div flex="cross:center main:right" class="textRight" flex-box="1" @click="share('shareQQ',2)">
			<img src="./images/qq.png" class="qqIcon"/>
			<div class="shareText">QQ</div>
		</div>
	</div>
</template>

<script>
    import API from '../api/api.js'
    const api = new API();
	export default {
		props:['piceIds','shareCode','imgUrl','shareUrl','id','index'],
		data () {
			return {
                shareInfo:''
			};
		},
		methods: {
            getShareInfo(typeName,type){
                let param = {
                    shareCode:this.shareCode,
                    classId: Uri.query().get('classId'),
                    tid:this.piceIds,
                };
                api.getShareInfo(param).then(res => {
                    let {code, rs} = res;
                    if (code == 200) {
                        this.shareInfo = rs;
                        this.shareTo(typeName,type);
                    }
				});
            },
            share(typeName,type) {
                if(this.shareCode=='APP_VIDEO_PIC'){
                    if(this.index||this.index===0){
                        this.$parent.dataList[this.index].shareCount++;
					}
				}
                this.getShareInfo(typeName,type);
			},
			shareTo(typeName,type){
                this.$util.JsBridge('shareTo', {
                    title:this.shareInfo.title,
                    imgUrl:this.imgUrl,
                    content:this.shareInfo.content,
                    shareType:typeName,
                    shareUrl:this.id?this.shareUrl+'&type='+type+'&piceIds='+this.piceIds+this.id:this.shareUrl+'&type='+type+'&piceIds='+this.piceIds
                }, (res) => {})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.shareCtrl {
		border-top: 0.01rem solid rgba(255, 255, 255, .1);
		padding: 0.13rem 0;
	}

	.shareText {
		font-size: 0.1rem;
		margin-left: 0.08rem;
	}

	.weixinIcon {
		width: 0.18rem;
		height: 0.15rem;
	}

	.pengyouquanIcon {
		width: 0.17rem;
		height: 0.17rem;
	}

	.qqIcon {
		width: 0.15rem;
		height: 0.16rem;
	}
</style>